package com.biostime.qdingding.modules.qd.api;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.biostime.qdingding.common.api.FastResponse;
import com.biostime.qdingding.common.api.ListResponse;
import com.biostime.qdingding.common.api.ObjResponse;
import com.biostime.qdingding.common.config.Global;
import com.biostime.qdingding.common.web.BaseController;
import com.biostime.qdingding.modules.qd.api.dto.ProvinceDto;
import com.biostime.qdingding.modules.qd.api.dto.SerAndLevAndSec;
import com.biostime.qdingding.modules.qd.api.dto.SmsDto;
import com.biostime.qdingding.modules.qd.api.dto.UploadResultDto;
import com.biostime.qdingding.modules.qd.api.dto.VersionUpdateDto;
import com.biostime.qdingding.modules.qd.entity.Album;
import com.biostime.qdingding.modules.qd.entity.Center;
import com.biostime.qdingding.modules.qd.entity.Contract;
import com.biostime.qdingding.modules.qd.entity.Member;
import com.biostime.qdingding.modules.qd.entity.Privilege;
import com.biostime.qdingding.modules.qd.entity.Student;
import com.biostime.qdingding.modules.qd.service.AlbumService;
import com.biostime.qdingding.modules.qd.service.AppVersionService;
import com.biostime.qdingding.modules.qd.service.CenterService;
import com.biostime.qdingding.modules.qd.service.ContractService;
import com.biostime.qdingding.modules.qd.service.CourselevelService;
import com.biostime.qdingding.modules.qd.service.CoursesectionService;
import com.biostime.qdingding.modules.qd.service.CourseserialService;
import com.biostime.qdingding.modules.qd.service.MemberService;
import com.biostime.qdingding.modules.qd.service.SmsService;
import com.biostime.qdingding.modules.sys.entity.Area;
import com.biostime.qdingding.modules.sys.entity.User;
import com.biostime.qdingding.modules.sys.service.AreaService;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageHelper;

/**
 * 基础模块
 * 
 * @author chenweicheng
 * @version 2015-11-06
 */
@RestController
@RequestMapping(value = "${adminPath}/qd/api/basic")
public class BasicApi extends BaseController {

	public static final String headImgCategory = "headImg";

	@Value("${sms.debug}")
	private boolean smsDebug;

	@Autowired
	private MemberService memberService;

	@Autowired
	private SmsService smsService;

	@Autowired
	private AreaService areaService;

	@Autowired
	private AlbumService albumService;

	@Autowired
	private CenterService centerService;

	@Autowired
	private CourseserialService serialService;
	
	@Autowired
	private CourselevelService levelService;
	
	@Autowired
	private CoursesectionService sectionService;
	
	@Autowired
	private ContractService contractService;
	
	@Autowired
	private AppVersionService versionService;
	
	//非会员，游客可以浏览的早教中心
	public static final int defaultCenterId = Integer.parseInt(Global.getConfig("defaultCenterId"));
	
	//非会员，孩子id
	public static final int defaultStudentId = Integer.parseInt(Global.getConfig("defaultStudentId"));
	
	//游客id
	public static final int defaultUserId = Integer.parseInt(Global.getConfig("defaultUserId"));

	/**
	 * 启动/更新检查
	 * 
	 * @param platform:ios(苹果),android(安卓)
	 * @return
	 */
	@RequestMapping(value = "versionUpdate")
	public ObjResponse<VersionUpdateDto> versionUpate(String userId,String platform) {
		String message = null;
		int errCode = 0;
		VersionUpdateDto dto = null;
		if (userId != null && !userId.equals("") && platform != null && !platform.equals("")) {
			List<VersionUpdateDto>  dtos = versionService.apiGetVersion(platform);
			if(dtos != null && !dtos.isEmpty()){
				dto = dtos.get(0);
			}
			message = "更新检查成功";
			errCode = 0;
		} else {
			message = "更新检查失败，参数有误";
			errCode = 1;
		}
		return FastResponse.create().errMsg(message).errCode(errCode).obj(dto);
	}
	
	/**
	 * 登录
	 */
	@RequestMapping(value = "login")
	public ObjResponse<Map<String, Object>> login(String mobile, String validateCode, HttpSession session) {
		String loginCode = (String) session.getAttribute("loginCode");
		String loginMobile = (String) session.getAttribute("loginMobile");
		String message = null;
		Member member = null;
		int errCode = 0;
		boolean flag = false;
		String rank = null;
		
		if (mobile != null && !mobile.equals("") && validateCode != null && !validateCode.equals("")) {
			
			// 假如为测试状态，则输入0707可登录
			if (validateCode.equals(loginCode) && mobile.equals(loginMobile)
					|| (smsDebug && validateCode.equals("9322")))
				flag = true;
			else {
				message = "登录失败,验证码错误";
				errCode = 1;
			}
		} else {
			message = "登录失败,参数不能为空";
			errCode = 1;
		}
		
		Map<String, Object> map = new HashMap<String, Object>();
		if (flag) {
			
			//通过电话号码查询会员
			member = memberService.getByMobile(mobile);
		
			if (member != null) {
				
				//用户头像
				List<Album> headAlbum = albumService.apiGet("headImg", member.getId());
				if(headAlbum != null && !headAlbum.isEmpty()){
					member.setAvatar(headAlbum.get(0).getOrginPath()); 
				}
				
				//通过会员查找学生
				Student student = contractService.apiContractByMember(member.getId());

				//通过合同查找早教中心,如果查找不到，则取默认早教中心
				Center center = null;
				if (student != null){
					center = centerService.getCenterByStudent(student);
				}else{
					student = new Student();
					student.setId(String.valueOf(defaultStudentId));
				}
				if(center == null){
					center = new Center();
					center.setId(String.valueOf(defaultCenterId));  
				}
				
				//判断是否是会员
				rank = memberService.memberRank_version2(student.getId());
				
				//学员列表
				List<Student> studentList = new ArrayList<Student>();
				studentList.add(student);
				member.setCenter(center);
				map.put("member", member);
				map.put("studentList", studentList);
				map.put("rank", rank);
				message = "登录成功";
				errCode = 0;
				
			} else {
				message = "登录失败,用户不存在";
				errCode = 1;
			}
		}
		return FastResponse.create().errMsg(message).errCode(errCode).obj(map);
	}
	
	/**
	 * 登录
	 * 为适应新需求： 切换宝宝
	 * 新增版本2登陆接口
	 */
	@RequestMapping(value = "login_version2")
	public ObjResponse<Map<String, Object>> login_version2(String mobile, String validateCode, HttpSession session) {
		String loginCode = (String) session.getAttribute("loginCode");
		String loginMobile = (String) session.getAttribute("loginMobile");
		String message = null;
		Member member = null;
		int errCode = 0;
		boolean flag = false;
		String rank = null;
		
		if (mobile != null && !mobile.equals("") && validateCode != null && !validateCode.equals("")) {
			
			// 假如为测试状态，则输入0707可登录
			if (validateCode.equals(loginCode) && mobile.equals(loginMobile)
					|| (smsDebug && validateCode.equals("9322")))
				flag = true;
			else {
				message = "登录失败,验证码错误";
				errCode = 1;
			}
		} else {
			message = "登录失败,参数不能为空";
			errCode = 1;
		}
		
		Map<String, Object> map = new HashMap<String, Object>();
		if (flag) {
			
			//通过电话号码查询会员
			member = memberService.getByMobile(mobile);
		
			if (member != null) {
				
				//用户头像
				List<Album> headAlbum = albumService.apiGet("headImg", member.getId());
				if(headAlbum != null && !headAlbum.isEmpty()){
					member.setAvatar(headAlbum.get(0).getOrginPath()); 
				}
				
				
				//通过会员查找学生
				//学员列表
				List<Student> studentList = contractService.apiContractByMember_version2(member.getId());

				//通过合同查找早教中心,如果查找不到，则取默认早教中心
				Center center = null;
				if (studentList != null && !studentList.isEmpty()){
					center = centerService.getCenterByStudent(studentList.get(0));
				}else{
					studentList  = new ArrayList<Student>();
					Student student = new Student();
					student.setId(String.valueOf(defaultStudentId));
					studentList.add(student);
				}
				if(center == null){
					center = new Center();
					center.setId(String.valueOf(defaultCenterId));  
				}
				
				//判断是否是会员
				rank = memberService.memberRank_version2(studentList.get(0).getId()); 
				
				member.setCenter(center);
				map.put("member", member);
				map.put("studentList", studentList);
				map.put("rank", rank);
				message = "登录成功";
				errCode = 0;
				
			} else {
				message = "登录失败,用户不存在";
				errCode = 1;
			}
		}
		return FastResponse.create().errMsg(message).errCode(errCode).obj(map);
	}	

	/**
	 * 注册/获取注册短信验证码
	 */
	@RequestMapping(value = "getRegisterCode")
	public ObjResponse<String> getRegisterCode(String mobile, HttpSession session) {
		int errCode = 1;
		String message = "获取验证码失败";
		SmsDto sd = null;
		if (mobile != null && !mobile.equals("")) {
			String code = smsService.getRandomText();
			sd = smsService.sendMsg(mobile, code);
			if ("0".equals(sd.getReturn())) {
				message = sd.getInfo();
				errCode = 0;
				session.setAttribute("regCode", code);
				session.setAttribute("regMobile", mobile);
			} else {
				message = sd.getInfo();
				errCode = 1;
			}
		}
		return FastResponse.create().errCode(errCode).errMsg(message).obj("");
	}

	/**
	 * 注册/获取注册短信验证码
	 */
	@RequestMapping(value = "getRegisterCode_version2")
	public ObjResponse<String> getRegisterCode_version2(String mobile, HttpSession session) {
		int errCode = 1;
		String message = "获取验证码失败";
		SmsDto sd = null;
		Member member = memberService.getByMobile(mobile);
		if (mobile != null && !mobile.equals("")) {
			if(member == null){
				String code = smsService.getRandomText();
				sd = smsService.sendMsg(mobile, code);
				if ("0".equals(sd.getReturn())) {
					message = sd.getInfo();
					errCode = 0;
					session.setAttribute("regCode", code);
					session.setAttribute("regMobile", mobile);
				} else {
					message = sd.getInfo();
					errCode = 1;
				}				
			}else{
				message = "该手机号码已注册过";
				errCode = 1;
			}

		}
		return FastResponse.create().errCode(errCode).errMsg(message).obj("");
	}	
	
	/**
	 * 注册/获取登录短信验证码
	 */
	@RequestMapping(value = "getLoginCode")
	public ObjResponse<String> getLoginCode(String mobile, HttpSession session) {
		int errCode = 1;
		String message = "获取验证码失败";
		SmsDto sd = null;
		if (mobile != null && !mobile.equals("")) {
			String code = smsService.getRandomText();
			sd = smsService.sendMsg(mobile, code);
			if ("0".equals(sd.getReturn())) {
				message = sd.getInfo();
				errCode = 0;
				session.setAttribute("loginCode", code);
				session.setAttribute("loginMobile", mobile);
			} else {
				message = sd.getInfo();
				errCode = 1;
			}
		}
		return FastResponse.create().errCode(errCode).errMsg(message).obj("");
	}
	
	/**
	 * 注册/获取登录短信验证码
	 */
	@RequestMapping(value = "getLoginCode_version2")
	public ObjResponse<String> getLoginCode_version2(String mobile, HttpSession session) {
		int errCode = 1;
		String message = "获取验证码失败";
		SmsDto sd = null;
		Member member = memberService.getByMobile(mobile);
		if (mobile != null && !mobile.equals("")) {
			if(member != null){
				String code = smsService.getRandomText();
				sd = smsService.sendMsg(mobile, code);
				if ("0".equals(sd.getReturn())) {
					message = sd.getInfo();
					errCode = 0;
					session.setAttribute("loginCode", code);
					session.setAttribute("loginMobile", mobile);
				} else {
					message = sd.getInfo();
					errCode = 1;
				}				
			}else{
				message = "该手机号码尚未注册";
				errCode = 1;
			}
		}
		return FastResponse.create().errCode(errCode).errMsg(message).obj("");
	}	

	/**
	 * 获取区域列表
	 * 
	 * @return 区域列表
	 */
	@RequestMapping(value = "getDistrictList")
	public ListResponse<ProvinceDto> getDistrictList() {
		List<ProvinceDto> list = areaService.apiGetAreaList();
		return FastResponse.create().errCode(0).list(list);
	}
	
	/**
	 * 获取早教中心列表
	 * 
	 * @return 早教中心列表
	 */
	@RequestMapping(value = "getCenterList")
	public ListResponse<Center> getCenterList(int pageindex ,int pagesize) {
		PageHelper.startPage(pageindex, pagesize);
		List<Center> centerList = centerService.apiGetCenterList();
		return FastResponse.create().errCode(0).list(centerList);
	}	

	/**
	 * 注册/会员注册
	 * 
	 */
	@SuppressWarnings({ "deprecation", "unchecked" })
	@Transactional
	@RequestMapping(value = "register")
	public ObjResponse<HashMap<String,Object>> register(HttpServletRequest request, HttpServletResponse response, HttpSession session)
			throws JsonParseException, JsonMappingException, IOException {
		String message = null;
		String mobile = request.getParameter("mobile");
		String districtId = request.getParameter("districtId");
		String nickName = request.getParameter("nickName");
		String validateCode = request.getParameter("validateCode");
		String picRes = request.getParameter("picRes");
		String regCode = (String) session.getAttribute("regCode");
		String regMobile = (String) session.getAttribute("regMobile");
		if (picRes != null)
			picRes = picRes.replaceAll(".*\\[", "[").replaceAll("\\].*", "]");// 只取list的内容
		int errCode = 0;
		int subCode = 0;
		Area area = null, city = null;
		Center center = null;
		String rank = null;

		//参数校验
		boolean flag = false;
		if ((districtId != null && !districtId.equals("")) && (nickName != null && !nickName.equals(""))
				&& picRes != null && !picRes.equals("") && (mobile != null && !mobile.equals(""))
				&& (validateCode != null && !validateCode.equals(""))) {
			if (mobile.equals(regMobile) && validateCode.equals(regCode) || (smsDebug && validateCode.equals("9322"))) {
				area = areaService.get(new Area(districtId));
				city = areaService.get(new Area(area.getParentId()));
				if (area != null && city != null) {
//					center = centerService.getCenterByArea(area);
					flag = true;
				} else {
					errCode = 1;
					subCode = 1;
					message = "区域错误";
				}
			} else {
				errCode = 1;
				subCode = 1;
				message = "验证码错误";
			}
		} else {
			errCode = 1;
			subCode = 1;
			message = "参数不能为空";
			if(picRes==null||picRes.equals("")){
				errCode=1;
				subCode=1;
				message="图片不能为空";
			}
		}
		Member member = null;

		if (flag == true) {
			if (memberService.getByMobile(mobile) == null) {
				ObjectMapper mapper = new ObjectMapper();
				JavaType javaType = mapper.getTypeFactory().constructParametricType(List.class, UploadResultDto.class);
				List<UploadResultDto> uploadList = (List<UploadResultDto>) mapper.readValue(picRes, javaType);
				UploadResultDto urd = null;
				if (uploadList != null && uploadList.size() > 0)
					urd = uploadList.get(0);
				member = new Member();
				member.setMobile(mobile);
				member.setNikename(nickName);
				member.setCityId(Integer.parseInt(city.getId()));
				member.setProviceId(Integer.parseInt(city.getParentId()));
				member.setAreaId(Integer.parseInt(districtId));
				member.setDistrict(area.getName());
				member.setAvatar(urd.getPath());
				member.setCreateBy(new User("0"));
				member.setCreateDate(new Date());
				member.setUpdateBy(new User("0"));
				member.setUpdateDate(new Date());
				member.setLoginFlag("0");
				int i = memberService.apiInsert(member);

				// 在album中添加记录
				if (urd != null) {
					urd = uploadList.get(0);
					Album a = new Album();
					a.setAlbumSize(urd.getSize());
					a.setCategory("headImg");
					a.setObjectId(Integer.parseInt(member.getId()));
					a.setOrginPath(urd.getPath());
					a.setThumbPath(urd.getThumb());
					a.setFileName(urd.getName());
					a.setCreateBy(new User("0"));
					a.setCreateDate(new Date());
					a.setUpdateBy(new User("0"));
					a.setUpdateDate(new Date());
					a.setDelFlag("0");
					albumService.apiInsert(a);
				}
				if (i != 0) {
					message = "会员注册成功";
					subCode = 1;
					errCode = 0;
				} else {
					message = "会员注册失败";
					subCode = 1;
					errCode = 1;
				}
			} else {
				message = "会员注册失败，该手机号码已被注册过";
				subCode = 1;
				errCode = 1;
			}
		}

		//通过会员查找学生
		List<Student> studentList = new ArrayList<Student>();		
		if (member != null){
					
			Student student = contractService.apiContractByMember(member.getId());
						
			//通过合同查找早教中心
			if (student != null){
				center = centerService.getCenterByStudent(student);
			}else{
				student = new Student();
				student.setId(String.valueOf(defaultStudentId));
			}
			
			//如果查找不到，则取默认早教中心
			if(center == null){
				center = new Center();
				center.setId(String.valueOf(defaultCenterId));  
			}
			
			member.setCenter(center);
			studentList.add(student);
			
			//判断是否是会员
			rank = memberService.memberRank_version2(student.getId());
		}
		
		
		//将用户信息放进一个map
		HashMap<String,Object>  map = new HashMap<String,Object>();
		map.put("member", member);
		map.put("studentList", studentList);
		map.put("rank", rank);
		
		return FastResponse.create().errMsg(message).errCode(errCode).subCode(subCode).obj(map);
		
	}
	
	/**
	 * 注册/会员注册
	 * 版本2,返回默认学生
	 */
	@SuppressWarnings({ "deprecation", "unchecked" })
	@Transactional
	@RequestMapping(value = "register_version2")
	public ObjResponse<HashMap<String,Object>> register_version2(HttpServletRequest request, HttpServletResponse response, HttpSession session)
			throws JsonParseException, JsonMappingException, IOException {
		String message = null;
		String mobile = request.getParameter("mobile");
		String districtId = request.getParameter("districtId");
		String nickName = request.getParameter("nickName");
		String validateCode = request.getParameter("validateCode");
		String picRes = request.getParameter("picRes");
		String regCode = (String) session.getAttribute("regCode");
		String regMobile = (String) session.getAttribute("regMobile");
		if (picRes != null)
			picRes = picRes.replaceAll(".*\\[", "[").replaceAll("\\].*", "]");// 只取list的内容
		int errCode = 0;
		int subCode = 0;
		Area area = null, city = null;
		Center center = null;
		String rank = null;

		//参数校验
		boolean flag = false;
		if ((districtId != null && !districtId.equals("")) && (nickName != null && !nickName.equals(""))
				&& picRes != null && !picRes.equals("") && (mobile != null && !mobile.equals(""))
				&& (validateCode != null && !validateCode.equals(""))) {
			if (mobile.equals(regMobile) && validateCode.equals(regCode) || (smsDebug && validateCode.equals("9322"))) {
				area = areaService.get(new Area(districtId));
				city = areaService.get(new Area(area.getParentId()));
				if (area != null && city != null) {
//					center = centerService.getCenterByArea(area);
					flag = true;
				} else {
					errCode = 1;
					subCode = 1;
					message = "区域错误";
				}
			} else {
				errCode = 1;
				subCode = 1;
				message = "验证码错误";
			}
		} else {
			errCode = 1;
			subCode = 1;
			message = "参数不能为空";
			if(picRes==null||picRes.equals("")){
				errCode=1;
				subCode=1;
				message="图片不能为空";
			}
		}
		Member member = null;

		if (flag == true) {
			if (memberService.getByMobile(mobile) == null) {
				ObjectMapper mapper = new ObjectMapper();
				JavaType javaType = mapper.getTypeFactory().constructParametricType(List.class, UploadResultDto.class);
				List<UploadResultDto> uploadList = (List<UploadResultDto>) mapper.readValue(picRes, javaType);
				UploadResultDto urd = null;
				if (uploadList != null && uploadList.size() > 0)
					urd = uploadList.get(0);
				member = new Member();
				member.setMobile(mobile);
				member.setNikename(nickName);
				member.setCityId(Integer.parseInt(city.getId()));
				member.setProviceId(Integer.parseInt(city.getParentId()));
				member.setAreaId(Integer.parseInt(districtId));
				member.setDistrict(area.getName());
				member.setAvatar(urd.getPath());
				member.setCreateBy(new User("0"));
				member.setCreateDate(new Date());
				member.setUpdateBy(new User("0"));
				member.setUpdateDate(new Date());
				member.setLoginFlag("0");
				int i = memberService.apiInsert(member);

				// 在album中添加记录
				if (urd != null) {
					urd = uploadList.get(0);
					Album a = new Album();
					a.setAlbumSize(urd.getSize());
					a.setCategory("headImg");
					a.setObjectId(Integer.parseInt(member.getId()));
					a.setOrginPath(urd.getPath());
					a.setThumbPath(urd.getThumb());
					a.setFileName(urd.getName());
					a.setCreateBy(new User("0"));
					a.setCreateDate(new Date());
					a.setUpdateBy(new User("0"));
					a.setUpdateDate(new Date());
					a.setDelFlag("0");
					albumService.apiInsert(a);
				}
				if (i != 0) {
					message = "会员注册成功";
					subCode = 1;
					errCode = 0;
				} else {
					message = "会员注册失败";
					subCode = 1;
					errCode = 1;
				}
			} else {
				message = "会员注册失败，该手机号码已被注册过";
				subCode = 1;
				errCode = 1;
			}
		}

		//通过会员查找学生
		List<Student> studentList = null;
		if (member != null){
					
			//通过合同获取学生列表
			studentList = contractService.apiContractByMember_version2(member.getId());					
			if(studentList != null && !studentList.isEmpty()){
				
				//通过合同查找早教中心
				Student student = studentList.get(0);
				if (student != null){
					center = centerService.getCenterByStudent(student);
				}else{
					student = new Student();
					student.setId(String.valueOf(defaultStudentId));
				}
				
				//如果查找不到，则取默认早教中心
				if(center == null){
					center = new Center();
					center.setId(String.valueOf(defaultCenterId));  
				}
				
				member.setCenter(center);
				studentList.add(student);
				
				//判断是否是会员
				rank = memberService.memberRank_version2(student.getId());
			}
			
		}
				
		//将用户信息放进一个map
		HashMap<String,Object>  map = new HashMap<String,Object>();
		map.put("member", member);
		map.put("studentList", studentList);
		map.put("rank", rank);
		
		return FastResponse.create().errMsg(message).errCode(errCode).subCode(subCode).obj(map);
		
	}	
	

	/**
	 * App使用协议
	 */
	@RequestMapping(value = "useAgreement")
	public ObjResponse<String> useAgreement(String url) {
		String message = null;
		int errCode = 0;
		if (url != null && !url.equals("")) {
			message = "获取App使用协议成功";
			errCode = 0;
		} else {
			message = "获取App使用协议失败";
			errCode = 1;
		}
		return FastResponse.create().errMsg(message).errCode(errCode).obj("");
	}

	/**
	 * 获取Serial列表和Level列表和section列表
	 */
	@RequestMapping(value = "getSerAndLevAndSec")
	public ObjResponse<SerAndLevAndSec> getSerAndLevAndSec(String userId, String studentId,String centerId) {	
		String message = null;
		SerAndLevAndSec dto = null;
		List<HashMap<String, Object>> serialList = null;
		List<HashMap<String, Object>> levelList = null;	
		List<HashMap<String, Object>> sectionList = null;	
		int errCode = 0;
	
		if (userId != null && !userId.equals("") && centerId != null && !centerId.equals("")) {		
			dto = new SerAndLevAndSec();
		
			//课程系列列表
			serialList = serialService.apiFindList(centerId);
			
			//年龄段列表
			levelList = levelService.apiFindList(centerId);
			
			//上课时间段列表
			sectionList = sectionService.apiGetSection(centerId);
			
			dto.setSerialList(serialList);
			dto.setLevelList(levelList); 
			dto.setSectionlist(sectionList); 
			message = "获取课程系列和年龄段列表成功";
			errCode = 0;
			
		} else {
			message = "获取课程系列和年龄段列表失败，参数有误";
			errCode = 1;
		}
		
		return FastResponse.create().errMsg(message).errCode(errCode).obj(dto);
	}
	
	/**
	 * 新建临时合同测试
	 */
	@RequestMapping(value = "test")
	public String test() {	 
		
		Contract contract = new Contract();
		
		//会员
		Member member = new Member();
		member.setId("0"); 
		member.setName("陈伟成");
		contract.setMember(member);
		
		//中心
		Center center= new Center();
		center.setId(String.valueOf(BasicApi.defaultCenterId)); 
		contract.setCenter(center);
		
		//中止特权
		contract.setAbortPriv(new Privilege());
		
		//请假特权
		contract.setLeavePriv(new Privilege());
		
		//学员
		Student student = new Student();
		student.setId("0");
		student.setName("陈伟成宝宝");
		contract.setStudent(student); 
		
		memberService.newTemporaryContract(contract);
		
		return "success";
	}

}
